home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / streambu.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  6.5 KB  |  290 lines

  1. #ifndef __STREAMBU_CC
  2. #define __STREAMBU_CC
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * streambuf.cc - Definitions for the Standard Library stream buffers
  8.  *
  9.  * $Id: streambuf.cc,v 1.39 1996/09/13 23:39:36 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #ifndef _RWSTD_NO_NAMESPACE
  46. namespace std {
  47. #endif
  48.  
  49. /*
  50.  * class basic_streambuf<charT, traits>
  51.  *
  52.  */
  53.  
  54. /*
  55.  * ~basic_streambuf()
  56.  */
  57.  
  58. template<class charT, class traits>
  59. basic_streambuf<charT, traits>::~basic_streambuf()
  60. {
  61.  
  62. }
  63.  
  64. /*
  65.  * basic_streambuf()
  66.  */
  67.  
  68. template<class charT, class traits>
  69. basic_streambuf<charT, traits>::basic_streambuf()
  70. {
  71.   streambuf_init();
  72. }
  73.  
  74. /*
  75.  * void streambuf_init()
  76.  */
  77.  
  78. template<class charT, class traits>
  79. void basic_streambuf<charT, traits>::streambuf_init(bool set_mode)
  80. {
  81.   if ( set_mode )
  82.   mode_ = ( ios_base::in | ios_base::out );
  83.  
  84.   gbeg_ = 0;
  85.   gnext_ = 0;
  86.   gend_ = 0;
  87.  
  88.   pbeg_ = 0;
  89.   pnext_ = 0;
  90.   pend_ = 0;
  91. }
  92.  
  93.  
  94. /*
  95.  * int_type overflow(int_type)
  96.  */
  97.  
  98. template<class charT, class traits>
  99. _TYPENAME basic_streambuf<charT, traits>::int_type
  100. basic_streambuf<charT, traits>::overflow(int_type )
  101. {
  102.   return traits::eof();  
  103. }
  104.  
  105. /*
  106.  * int_type pbackfail(int_type)
  107.  */
  108.  
  109. template<class charT, class traits>
  110. _TYPENAME basic_streambuf<charT, traits>::int_type
  111. basic_streambuf<charT, traits>::pbackfail(int_type )
  112. {
  113.   return traits::eof();
  114. }
  115.  
  116. /*
  117.  * int showmanyc()
  118.  */
  119.  
  120. template<class charT, class traits>
  121. int basic_streambuf<charT, traits>::showmanyc()
  122. {
  123.   if ( gptr() )
  124.    {
  125.       if ( pptr()>egptr() ) setg(eback(),gptr(),pptr());
  126.    }
  127.   else
  128.     if ( pptr() ) setg(pbase(),pbase(),pptr());
  129.  
  130.   return (int)(egptr()-gptr());
  131. }
  132.  
  133. /*
  134.  * int_type underflow()
  135.  */
  136.  
  137. template<class charT, class traits>
  138. _TYPENAME basic_streambuf<charT, traits>::int_type
  139. basic_streambuf<charT, traits>::underflow()
  140. {
  141.   return traits::eof();
  142. }
  143.  
  144. /*
  145.  * int_type uflow()
  146.  */
  147.  
  148. template<class charT, class traits>
  149. _TYPENAME basic_streambuf<charT, traits>::int_type
  150. basic_streambuf<charT, traits>::uflow()
  151. {
  152.   if( traits::eq_int_type(underflow(),traits::eof()) )
  153.     return traits::eof();
  154.  
  155.  
  156.    return sbumpc();
  157. }
  158.  
  159. /*
  160.  * streamsize xsgetn(char_type *, streamsize)
  161.  */
  162.  
  163. template<class charT, class traits>
  164. streamsize basic_streambuf<charT, traits>::
  165. xsgetn(char_type *s, streamsize n)
  166. {
  167.   if ( !s || (n==0) ) return 0;
  168.  
  169.   streamsize i = ( in_avail() > n ) ? n : in_avail();
  170.   int_type   c;
  171.  
  172.   if(i > 0) {
  173.     s = traits::copy(s, gptr(), i);
  174.     s += i;
  175.     gbump(i);
  176.   }
  177.  
  178.   while((i < n) && ( !traits::eq_int_type( (c = sbumpc()),traits::eof()))) {
  179.     *s++ = traits::to_char_type(c);
  180.     ++i;
  181.   }
  182.  
  183.   return i;
  184. }
  185.  
  186. /*
  187.  * streamsize xsputn(const char_type *, streamsize)
  188.  */
  189.  
  190. template<class charT, class traits>
  191. streamsize basic_streambuf<charT, traits>::
  192. xsputn(const char_type *s, streamsize n)
  193. {
  194.   if ( !s || (n == 0) ) return 0;
  195.  
  196.   int         i=0;
  197.  
  198.   while((i < n) && ( !traits::eq_int_type(sputc(*s++),traits::eof()))) {
  199.     i++;
  200.   }
  201.  
  202.   return i;
  203.  }
  204.  
  205. /*
  206.  * pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode)
  207.  */
  208.  
  209. template<class charT, class traits>
  210. _TYPENAME basic_streambuf<charT, traits>::pos_type
  211. basic_streambuf<charT, traits>::
  212. seekoff(off_type , ios_base::seekdir , ios_base::openmode )
  213. {
  214.   return pos_type(off_type(-1));
  215. }
  216.  
  217. /*
  218.  * pos_type seekpos(pos_type, ios_base::openmode)
  219.  */
  220.  
  221. template<class charT, class traits>
  222. _TYPENAME basic_streambuf<charT, traits>::pos_type
  223. basic_streambuf<charT, traits>::
  224. seekpos(pos_type , ios_base::openmode )
  225. {
  226.   return pos_type(off_type(-1));
  227. }
  228.  
  229. /*
  230.  * basic_streambuf *setbuf(char_type *, streamsize)
  231.  */
  232.  
  233. template<class charT, class traits>
  234. basic_streambuf<charT, traits> *
  235. basic_streambuf<charT, traits>::setbuf(char_type*, streamsize )
  236. {
  237.   return this;
  238. }
  239.  
  240. /*
  241.  * int sync()
  242.  */
  243.  
  244. template<class charT, class traits>
  245. int basic_streambuf<charT, traits>::sync()
  246. {
  247.   return 0;
  248. }
  249.  
  250.  
  251. /*
  252.  * locale pubimbue(const locale& loc)
  253.  */
  254.  
  255. template<class charT, class traits>
  256. locale basic_streambuf<charT, traits>::pubimbue(const locale& loc)
  257. {
  258.   locale tmp = getloc();
  259.   imbue(loc);
  260.   return tmp; 
  261. }
  262.  
  263. /*
  264.  * locale getloc() const
  265.  */
  266.  
  267. template<class charT, class traits>
  268. locale basic_streambuf<charT, traits>::getloc() const
  269. {
  270.   return loc_buf;
  271. }
  272.  
  273. /*
  274.  * virtual void imbue(const locale& loc)
  275.  */
  276.  
  277. template<class charT, class traits>
  278. void basic_streambuf<charT, traits>::imbue(const locale& loc)
  279. {
  280.   loc_buf = loc;
  281.  
  282. }
  283.  
  284. #ifndef _RWSTD_NO_NAMESPACE
  285. }
  286. #endif
  287.  
  288. #pragma option pop
  289. #endif /* __STREAMBU_CC */
  290.